﻿layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;


    $(".allMoney").click(function () {
        $("#ExtractRMBMoney").val($("#totalMoney").text());
    });

    form.on("submit(addManager)", function (data) {
        //获取防伪标记
        $.ajax({
            type: 'POST',
            url: '/RebateExtract/AddOrModify/',
            data: {
                Id: $("#Id").val(),  //主键
                ExtractRMBMoney: $(".ExtractRMBMoney").val(),
                BankCard: $(".BankCard").val()
            },
            dataType: "json",
            headers: {
                "X-CSRF-TOKEN-yilezhu": $("input[name='AntiforgeryKey_yilezhu']").val()
            },
            success: function (res) {//res为相应体,function为回调函数
                if (res.ResultCode === 200) {
                    var alertIndex = layer.alert(res.ResultMsg, { icon: 1 }, function () {
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                        top.layer.close(alertIndex);
                    });
                }
                else {
                    layer.alert(res.ResultMsg, { icon: 5 });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, { icon: 5 });
            }
        });
        return false;
    });
    form.verify({
        money: function (value, item) { //value：表单的值、item：表单的DOM对象
            var totalMoney = parseFloat($("#totalMoney").text());
            var currentMoney = parseFloat(value);
            if (totalMoney >= 2) {
                if (currentMoney >= 2 && currentMoney <= 50000) {
                    if (currentMoney > totalMoney) {
                        return '余额不足。';
                    }
                } else {
                    return '提现金额必须大于2元且不超过5万,手续费2元。';
                }
            } else {
                return '余额不足。';
            }
        }
    });
});